home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / CPUID.ASM < prev    next >
Assembly Source File  |  1993-08-09  |  2KB  |  99 lines

  1. ; Test processor type. Origins of this code unknown - modified for
  2. ; Turbo C by KA9Q 5 Feb 90
  3.  
  4.         .MODEL  LARGE,C
  5.         LOCALS
  6.         %MACS
  7.         .LALL
  8.  
  9. p_80386   equ   7
  10. p_80286   equ   6
  11. p_80186   equ   5
  12. p_80188   equ   4
  13. p_v30     equ   3
  14. p_v20     equ   2
  15. p_8086    equ   1
  16. p_8088    equ   0
  17.  
  18.         .CODE
  19.  
  20. ;-- call from C : int getproc( void );
  21. ;-- gives the type of processor back , see equates
  22.         public getproc
  23. getproc proc
  24.  
  25.         pushf            ; save flags
  26.  
  27.         ;-- check 80386/80286
  28.         xor  ax,ax
  29.         push ax
  30.         popf            ; get it as flags
  31.         pushf
  32.         pop  ax         ; and get back as AX again
  33.         and  ax,0f000h  ; mask off high nibble
  34.         cmp  ax,0f000h
  35.         je   forget386  ; if true, no 80386 or 80286
  36.  
  37.         ;-- check if 80286 or 80386
  38.         mov  dl,p_80286
  39.         mov  ax,07000h
  40.         push ax
  41.         popf
  42.         pushf
  43.         pop  ax
  44.         and  ax,07000h  ; mask off
  45.         je   p_end      ; if bits 12-14 = 0 -> 80286
  46.         inc  dl         ; no , 80386
  47.         jmp  p_end
  48.  
  49.         ;-- check 80186/80188
  50. forget386 label near
  51.         mov  dl,p_80188
  52.         mov  al,0ffh
  53.         mov  cl,021h
  54.         shr  al,cl
  55.         jne  t88_86
  56.  
  57.         ;-- check V20/V30
  58.         mov  dl,p_v20
  59.         sti
  60.         push si
  61.         mov  si,0
  62.         mov  cx,0ffffh          ; read complete segment
  63.         rep  lods byte ptr es:[si]      ; REP with segment override works
  64.                                 ; only with V20 and V30
  65.         pop  si
  66.         or   cx,cx              ; check if whole segment read
  67.         je   t88_86             ; jip ! -> V20 or V30
  68.  
  69.         mov  dl,p_8088          ; no should be 8088 or 8086
  70.  
  71.         ;-- check 8088/8086 or V20/V30
  72. t88_86  label near
  73.         push cs                 ; swap cs and es
  74.         pop  es
  75.         std
  76.         mov  di,offset q_end
  77.         mov  al,0fbh            ; instruction code for STI
  78.         mov  cx,3
  79.         cli
  80.         rep  stosb
  81.         cld
  82.         nop
  83.         nop
  84.         nop
  85.  
  86.         inc  dx
  87.         nop
  88. q_end:  sti
  89.  
  90. p_end   label near          ; tests complete
  91.         popf
  92.         xor  dh,dh
  93.         mov  ax,dx          ; processorcode is return value
  94.         ret
  95.  
  96. getproc  endp
  97.         end
  98.  
  99.